package com.kinyx.framework.db.defines;

import java.util.Date;

import com.kinyx.framework.annotation.assist.ReturnNotNull;
import com.kinyx.framework.business.KRandomUtils;
import com.kinyx.framework.enums.impl.RandomRange;
import com.kinyx.framework.utils.KDateTimeUtils;

/**
 * 主键生成器
 */
public interface IPKGenerator {

	/**
	 * 生成主键
	 * @param length 长度
	 * @return 非null
	 */
	@ReturnNotNull
	default String id(final int length) {
		final String pattern = "yyyyMMddHHmmssSSS";
		return KDateTimeUtils.toString(new Date(), pattern) + KRandomUtils.randomString(false, length - pattern.length(), RandomRange.NUMBER_AND_LETTER_FULL);
	}

}
